%%Finding gamma ind the NW UEP method

clear
close all
clc

fig = figure;

set(fig,'Color','w');



q=2^1;

lm=['s','o'];

%gamma=[0.3 0.7];
%gamma=[0.5 0.5];
gamma=[0.7 0.3];


colors=['k','k','k'];

%Size of the layers
K=[32 64];

number_of_layers=2;
number_of_packets = 200;
result = zeros(number_of_layers,number_of_packets);

packet_67_results = zeros(1,100);

hold on

L1 = 0.01:0.01:1;
L2 = 0.01:0.01:1;

for a=1:100
    
    
    
    gamma=[L1(a) L2(101-a)];
    
    result = zeros(number_of_layers,number_of_packets);
    
    for layer=1:number_of_layers
        
        S = zeros(K(layer)+1);
        S(1,1)=1;
        P = zeros(K(layer)+1);
        r=0:length(P);
        
        
        
        
        
        
        for packets=1:number_of_packets
            
            state=1;
            for n = 1:length(P)
                
                if n==length(P)
                    P(state,state)=1;
                else
                    P(state,state) = 1-gamma(layer)*(1-1/q^(K(layer)-r(n)));
                    P(state,state+1) = gamma(layer)*(1-1/q^(K(layer)-r(n)));
                end
                
                state=state+1;
            end
            
            
            
            new = S(1,:)*(P^packets);
            result(layer,packets) = result(layer,packets) + new(1,length(P));
            
        end
        

    packet_67_results(a)=result(1,87);
    
    end
end

hold off

